Skip to content

u64x64 lab route G: NNUE-style accumulator over a bound 64×64 Boolean tile - #429

Merged
AdaWorldAPI merged 11 commits into
masterfrom
ccr-1fd55114-ndx7e4
Nov 15, 2026
Merged

AdaWorldAPI merged 11 commits into
masterfrom
ccr-1fd55114-ndx7e4

Conversation

@AdaWorldAPI

@AdaWorldAPI AdaWorldAPI commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Laboratory only: no src/ edit, no public type, no production caller.

Question

Can the existing 512-byte BitTile ([u64; 64], 4,096 cells: word k is category k, bit r is row r) be an exact, incrementally updatable NNUE-style feature surface?

The accumulator is h[j] = bias[j] + Σ_{(k, r) set} w[k][r][j] for j < 16.

Kinds kept apart

thing type meaning
tile bit presence set semantics; no sign, no count
weight i16 signed
accumulator i32 exact by an admitted bound: |bias| ≤ 2^15, w ≠ i16::MIN, so |h| < 2^28; refused at construction, never wrapped

64×64 (4,096 positional features), u64 × u64 (integer multiplication) and Σ c_L·c_R (bag cardinality) are three different operations. The tile is the first one only.

What

examples/u64x64/nnue.rs:

  • nnue_refresh: walks set bits with trailing_zeros and gathers one weight row per set bit.
  • nnue_update: d = old ^ new, adds the rows that turned on (d & new) and subtracts those that turned off (d & old). Correct only when the accumulator is that of old.
  • *_simd variants: the existing I32x16::from_i16_slice with Add/Sub; no new primitive.
  • nnue_refresh_simd2 / nnue_refresh_simd4: two and four independent accumulators. A recorded negative result.
  • PlaneWeights plus nnue_refresh_planes / nnue_refresh_abakus: per-bit addressing, described below.
  • refresh_bound / update_bound: read Source::present through fixture::Bound. An update refuses two frames of different sources (ForeignSource), shapes (Shape) or row orders (RowOrder), or without the presence field (Field), and leaves the accumulator untouched. Versions may differ: an update is between versions, and the older frame still binds to its own expectation.

examples/u64x64/nnue_main.rs (example u64x64_nnue): the benchmark, reusing the lab harness (counting allocator, tier line). The six refresh variants are interleaved within each sample, in rotated order.

Tests

tests/u64x64_nnue.rs, 12 tests, against an independent oracle that reads all 4,096 cells one bit at a time and sums in i64:

  • every single-cell tile (4,096), full-minus-one-cell both ways, empty, full, and random tiles at densities from 1/64 to 63/64, for every refresh and update variant;
  • 1,000 updates of 1, 8 or 64 cells, mixed on and off, each against a fresh refresh, then undone in reverse to the exact starting accumulator;
  • one cell toggled 101 times;
  • the bound's extremes in both directions, including uniform negative weights; refusals for i16::MIN, a bias past 2^15, and a 63-row table;
  • the four frame refusals, with the accumulator unchanged;
  • no allocation in refresh or update (a per-thread counter, shown to be live);
  • a count that reaches the Abakus counter's top column;
  • a counterexample: a tile is a set, so a bag with a repeated (k, r) edge is not equal to the tile's sum.

Disable runs, all red:

disabled tests that failed
update forgets removals 3
refresh skips bit 63 7
SIMD refresh drops the bias 5
row-order check removed 1
i16::MIN admitted 1
update ignores word 0 3
simd2 drops its second accumulator 2
planes: sign plane added instead of subtracted 1
planes skip the upper 8 lanes 1
Abakus drops the sixteens column 2
Abakus keeps the carry in its own column 2

Results: walk and update

AVX-512, read from the binary: avx512f=true avx512bw=true avx512vpopcntdq=true. Median of 31 samples × 2,000 calls.

Update on a half-full tile, ns per update:

changed bits placement scalar I32x16 half-tile refresh ÷ update
1 scattered 27.0 26.6 58×
8 scattered 38.2 42.6 37×
8 one word 33.3 32.4 48×
64 scattered 97.9 123.3 13×
64 one word 67.8 54.3 29×
1 same cell, repeated – 28.7 54×

Resident memory: weights 131,072 B (fits L2, not L1), tile 512 B, accumulator 64 B. Scratch: 0 B.

Against the predictions (pre-registered on the blackboard before the code was written):

  • P1, P2, P3, P6 hold.
  • P4 partly missed. A 1-bit update is 58× cheaper than a half-tile refresh, not the predicted ≥100×. The update scans all 64 words, and that floor (about 18 to 23 ns) is the cost of refreshing an empty tile.
  • P5 missed, kill not hit. The I32x16 walk is 1.06× the scalar one, not ≥2×. objdump shows LLVM compiles the scalar 16-lane add to the same vpmovsxwd + vpaddd.

Multi-accumulator refresh: hypothesis falsified

The hypothesis was that the walk is limited by the latency of the add chain on one accumulator. The kill condition was hit:

  • Two accumulators are 0.96× as fast as one on the half tile and 0.90× on the full tile.
  • Four accumulators are 0.64× as fast as two.

The one-accumulator loop is six instructions per set bit (tzcnt, shl, vpmovsxwd from memory, vpaddd, blsr, jne). The two-accumulator version adds a branch per pair of bits. The four-accumulator version spills its accumulator array to the stack.

Per-bit addressing: bit planes and the Abakus column counter

The weights are transposed once into bit planes: plane[b][k][j] is a u64 whose bit r is bit b of w[k][r][j]. That is 131,072 B, the same bytes as the weights. The refresh is then

h[j] = bias[j] + Σ_{b<15} 2^b·n[b][j] − 2^15·n[15][j], with n[b][j] = Σ_k popcount(tile[k] & plane[b][k][j]).

Bit 15 is the sign bit, hence the minus. The tile bit is read in place as the address and no row is gathered.

  • planes popcounts every word (U64x8, 8 output lanes per vector).
  • abakus adds the masks into carry-save columns: the full-adder law as ternlog 0x96 (sum) and 0xE8 (carry), with the carry moving to the adjacent column, using Harley-Seal over groups of 16 words. Each column is popcounted once.

ns per tile, the six variants interleaved. AVX-512 runs 1 and 3 (run 2 was disturbed); AVX2 all three runs:

tier tile set bits walk ×1 planes Abakus
AVX-512 empty 0 36.2 to 36.6 2,110 to 2,130 2,118 to 2,513
1/64 54 70.0 to 72.2 2,064 to 2,110 2,119 to 2,421
1/2 2,027 1,584 to 1,624 2,127 to 2,187 2,177 to 2,775
3/4 3,138 2,294 to 2,309 2,091 to 2,107 2,119 to 2,474
full 4,096 2,780 to 3,262 2,115 to 2,521 2,485 to 2,605
AVX2 1/2 2,027 1,694 to 2,568 6,135 to 8,454 4,693 to 6,271
full 4,096 3,286 to 3,401 6,088 to 6,542 4,678 to 4,954

Against the predictions:

  • R1 exact: holds.
  • R2 density-independent: holds.
  • R3 planes below 1,000 ns at half density: failed, kill hit. Planes take 2,127 to 2,187 ns there, slower than the walk.
  • R4 planes lose at 1/64: holds, by about 30×.
  • R5 Abakus no faster than planes on AVX-512: holds (0.79× to 1.00×). vpopcntq is one instruction.
  • R6 Abakus faster than planes on AVX2: holds, 1.30× to 1.46× at every density. U64x8::popcnt there is 8 scalar count_ones.

On AVX-512, planes beat the walk from about 3/4 density (1.10× at 3/4, about 1.3× full). On AVX2 the walk wins everywhere. The planes do fixed work: 2,048 U64x8 and+popcnt+add per refresh, touching all 4,096 cells × 16 lanes × 16 bits whether set or not. The walk touches one 32-byte row per set bit.

Not measured

  • NEON, wasm and scalar tiers.
  • What bounds the walk's per-bit cost (the widening load or the branch at each word end); this host has no hardware counters.
  • A source with real FK fan-out.
  • Multiplicity: a bag needs a count plane, not this tile.

Decision

Keep laboratory only.

  • The surface is exact, and the incremental update is 13× to 58× cheaper than a refresh.
  • The walk stays the reference refresh. Bit planes would pay only on dense tiles on AVX-512 (a measured dispatch, not a replacement).
  • The Abakus counter is the better plane form wherever the vector popcount is emulated.
  • No consumer exists yet. The update's per-word scan floor would need a changed-word index before a public primitive is worth it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
h = bias + sum of w[k][r] over the set cells of a 64x64 BitTile. refresh
walks set bits; update adds the rows of cells that turned on and
subtracts the rows that turned off, from old ^ new. Scalar and I32x16
(from_i16_slice) variants. Weights are i16, the accumulator i32, exact
by an admitted bound rather than by wrapping. Bound entry points read
Source::present through fixture::Bound and refuse frames of other
sources, shapes or row orders; versions may differ.

Tests check every route against a per-cell i64 oracle on all 4,096
single-cell tiles, empty, full and 200 random tiles, 1,000 mixed updates
undone in reverse, the bound extremes, refusals, zero allocation, and
the multiplicity counterexample (a tile is a set, a bag is not).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Registers the u64x64_nnue example (refresh against update, scalar against
I32x16, allocation guard, tier line) and records the measured results
against the pre-registered predictions on the blackboard: P1, P2, P3, P6
hold; the 1-bit update is 58x cheaper than a half-tile refresh, not 100x;
the I32x16 route is 1.06x scalar because LLVM already vectorizes the
scalar add.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: b5f8bf58-06c1-4614-8427-cffd17e52669
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@AdaWorldAPI
AdaWorldAPI marked this pull request as ready for review November 14, 2026 23:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-14T23:42:29.865464Z 82e54a9 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

nnue_refresh_simd2 alternates consecutive set bits between two I32x16
accumulators; nnue_refresh_simd4 round-robins over four. Both are
checked against the per-cell oracle on every corpus. The bench now
interleaves the four refresh variants per sample with a rotated order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Single-cell tiles never reach the second accumulator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
The weights are transposed once into bit planes (plane[b][k][j] holds
bit b of w[k][r][j] over rows r); the refresh then counts
popcount(tile[k] & plane) per bit and recombines with 2^b, the sign
plane negative. nnue_refresh_planes popcounts every word;
nnue_refresh_abakus adds the masks into carry-save columns (ternlog
0x96 / 0xE8, Harley-Seal over 16 words) and popcounts each column once.
Both are density-independent and checked against the per-cell oracle.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XAqKMNPpoyKDKuAgEnu6HU
@AdaWorldAPI
AdaWorldAPI merged commit 2102721 into master Nov 15, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants